package com.mms.web.interceptor;

import com.mms.utils.SysConst;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @auth wzy
 * @date 2023/11/16 10:45
 */
public class SysInterceptor extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        Object userSession = request.getSession().getAttribute(SysConst.SYS_USER_SESSION);

        if (userSession==null){
            response.sendRedirect( request.getContextPath()+"/"+SysConst.SYS_ERROR_PAGE);
            return false;
        }

        return true;
    }

}
